package ciyuan.Item.SkillBook;

import ciyuan.Entity.WindBall.WindBallEntity;
import ciyuan.Item.ItemGroups;
import ciyuan.Item.TypeInterface.SkillBookType;
import ciyuan.Player.Skill.SkillUtils;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceContext;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;

/**
 * @author 150149
 */
public class BlastBullet extends SkillBookType {

    public BlastBullet() {
        super(new Properties().tab(ItemGroups.SkillBook));
    }

    @Override
    public void keyDown(PlayerEntity playerEntity) {
        SkillUtils.setSkillColdInterval(playerEntity, this, 12 * 1000);

        if (playerEntity.level.isClientSide) {
            return;
        }
        SkillUtils.THREAD_POOL_EXECUTOR.execute(new Runnable() {

            @Override
            public void run() {
                for (int i=0;i<5;i++) {
                    BlockPos blockPos = SkillUtils.getPlayerSee(playerEntity.level,playerEntity, RayTraceContext.FluidMode.SOURCE_ONLY,30).getBlockPos();
                    Vector3d vector3d2 = playerEntity.getViewVector(1.0F);
                    WindBallEntity magicBallEntity1 = new WindBallEntity(playerEntity, 0, 0,0,playerEntity.level);
                    magicBallEntity1.moveTo(playerEntity.getX(),playerEntity.getY() + 1,playerEntity.getZ(),0.0F, 0.0F);
                    magicBallEntity1.shootFromRotation(playerEntity,playerEntity.xRot,playerEntity.yRot,0.0F, 1.5F, 0.0F);
                    magicBallEntity1.setOwner(playerEntity);
                    SkillUtils.addEntity(magicBallEntity1, playerEntity.level);
                    playerEntity.level.playSound(null, playerEntity.getX(), playerEntity.getY(), playerEntity.getZ(), SoundEvents.BLAZE_SHOOT, playerEntity.getSoundSource(), 1.0F, 1.0F);
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException ignored) { }
                }
            }
        });

        SkillUtils.saveSkillCastTime(playerEntity,this);
    }

    @Override
    public String getSkillCastName() {
        return "BlastBullet";
    }

    @Override
    public ITextComponent getSkillDescription() {
        return new TranslationTextComponent("ciyuan.skill.desc.28");
    }

    @Override
    public ITextComponent getSkillName() {
        return new TranslationTextComponent("ciyuan.skill.name.28");
    }
}
